package com.ss.whisper2.controller;

import com.ss.whisper2.pojo.entity.Article;
import com.ss.whisper2.service.ArticleService;
import com.ss.whisper2.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.concurrent.Future;

@Controller
public class IndexController {
	@Autowired
	ArticleService articleService;
	@Autowired
	CourseService courseService;
	@GetMapping("/welcome")
	public String welcome(Model model){
		model.addAttribute("articles",articleService.getArticles());
		TimeZone tz = TimeZone.getTimeZone("ETC/GMT-8");
		TimeZone.setDefault(tz);

		//设置日期格式
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		// new Date()为获取当前系统时间
		System.out.println(df.format(new Date()));

		/*for (Article a : articleService.getArticles()) {
			System.out.println(a.toString());
		}*/
		return "welcome";
	}
	@GetMapping("articles/{id}")
	public String welcome(@PathVariable("id")Integer id,Model model){
		model.addAttribute("article",articleService.getArticleById(id));
		return "article";
	}
}
